package tliasweb.controller;

import com.itcast.aliyunossspringbootautoconfigure.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import pojo.Result;

import java.io.IOException;

@RestController
public class UploadController {

    /**
     * 注入AliOSSUtils
     * */
    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    public Result upload(@RequestParam("image") MultipartFile file,
                         //required = false； 代表参数可以不传 可以为空
                         @RequestParam(value = "username", required = false) String username,
                         @RequestParam(value = "age", required = false)Integer age) throws IOException {
        // 上传到阿里云oss
        String url = aliOSSUtils.upload(file);
        return Result.success(url);
    }

}
